package com.johnson.news.activity;
import android.os.Bundle;
import android.text.TextUtils;

import com.johnson.news.R;
import com.johnson.news.databinding.ActivityFragmentContainerBinding;
import com.johnson.news.fragment.SearchFragment;
import com.youmbe.library.BaseBindingActivity;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

public class FragmentContainerActivity extends BaseBindingActivity<ActivityFragmentContainerBinding> {
    public static final String intent_key_action = "intent_key_action";
    public static final String intent_key_title = "intent_key_title";
    public static final int action_search = 1;
    String title;
    int action;
    FragmentManager fragmentManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void init() {
        action = getIntent().getIntExtra(intent_key_action, action_search);
        title = getIntent().getStringExtra(intent_key_title);
        fragmentManager = getSupportFragmentManager();
        dataBinding.fragmentTitle.setTitle(TextUtils.isEmpty(title) ? getString(R.string.app_name) : title);

        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        switch (action) {
            case action_search:
                SearchFragment searchFragment = SearchFragment.newInstance(null, null);
                fragmentTransaction.add(R.id.fragment_container, searchFragment);
                fragmentTransaction.commit();
                break;
        }
    }

    @Override
    public int getContentViewId() {
        return R.layout.activity_fragment_container;
    }
}
